package com.huage_06.lesson_04;

import java.util.*;

public class HashMapTest01 {
    public static void main(String[] args) {
        List<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();

        //创建HashMap
        HashMap<String,String> map1 = new HashMap<String,String>();
        map1.put("cardId","001");
        map1.put("amount","Lisa");
        map1.put("kind","gold");

        HashMap<String,String> map2 = new HashMap<String,String>();
        map2.put("cardId","002");
        map2.put("amount","LiMing");
        map2.put("kind","tie");

        HashMap<String,String> map3 = new HashMap<String,String>();
        map3.put("cardId","003");
        map3.put("amount","Zhangsan");
        map3.put("kind","lv");

        //存储
        list.add(map1);
        list.add(map2);
        list.add(map3);

        //遍历
        for (HashMap<String,String> maps : list){
            //HashMap遍历方式一 获取键值集合
            Set<String> keys = maps.keySet();
            for (String key : keys){
                String value = maps.get(key);
                System.out.println(key+":"+value);
            }
        }
        System.out.println("-------");
        for (HashMap<String,String> maps : list){
            //HashMap遍历方式二 键值对对象获取键和值
            Set<Map.Entry<String, String>> entries = maps.entrySet();
            for (Map.Entry<String, String> map : entries){
                String key = map.getKey();
                String value = map.getValue();
                System.out.println(key+":"+value);
            }
        }
    }
}
